package edu.fatec.model;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

public class Telefone {
	
	private int id;
	@Length(max=2)
	private int ddd;
	@NotEmpty
	@NotNull
	private String operadora;
	@Length(max=9)
	private int numero;
	
	public int getId() {
		return id;
	}
	public int getDDD() {
		return ddd;
	}
	public String getOperadora() {
		return operadora;
	}
	public int getNumero() {
		return numero;
	}
	public void setId(int id) {
		this.id = id;
	}
	public void setDDD(int ddd) {
		this.ddd = ddd;
	}
	public void setOperadora(String operadora) {
		this.operadora = operadora;
	}
	public void setNumero(int numero) {
		this.numero = numero;
	}
	public boolean validarTelefone(Telefone t) {
		ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
		Validator validator = (Validator) factory.getValidator();
		boolean validador = true;
		
		Set<ConstraintViolation<Telefone>> constraintViolations = validator.validate(t);
		
		if (constraintViolations.size() != 0 ){
			validador = false;
		}
		
		return validador;
	}

}
